package org.issaclu.springbootmybatis.user.controller;

import org.issaclu.springbootmybatis.user.bo.UserDetailBo;
import org.issaclu.springbootmybatis.user.dto.UserInfo;
import org.issaclu.springbootmybatis.user.dto.UserInfoDetail;
import org.issaclu.springbootmybatis.user.service.UserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserInfoController {

    private final Logger logger = LoggerFactory.getLogger(getClass());
    private final UserInfoService userInfoService;

    public UserInfoController(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }

    @PostMapping("/insertOne")
    public UserInfo insertOne(@RequestBody UserInfo userInfo) {
        return this.userInfoService.insert(userInfo);
    }

    @PostMapping("/select")
    public List<UserInfo> select(@RequestBody UserDetailBo param) {
        return this.userInfoService.query(param);
    }

    @GetMapping("/getById/{id}")
    public String getById(@PathVariable String id) {
        UserInfo result = userInfoService.getById(id);
        logger.info("查询结果: {}", result);
        return Thread.currentThread().getName();
    }

    @GetMapping({"/getByName/{name}","/getByName"})
    public List<UserInfoDetail> getByName(@PathVariable(required = false) String name) {
        List<UserInfoDetail> result = userInfoService.getInfoWithDetailByName(name);
        logger.info("查询结果: {}", result);
        return result;
    }

    @GetMapping("/getUserInfoWithDetail/{id}")
    public UserInfo getUserInfoWithDetail(@PathVariable String id) {
        return this.userInfoService.getUserInfoWithDetail(id);
    }
    @GetMapping("/getUserInfoWithDetail2/{id}")
    public UserInfo getUserInfoWithDetail2(@PathVariable String id) {
        return this.userInfoService.getUserInfoWithDetail2(id);
    }
    @GetMapping("/getUser/{id}")
    public UserInfo getUser(@PathVariable String id) {
        return this.userInfoService.getUser(id);
    }
    @GetMapping("/getUser2/{id}")
    public UserInfo getUser2(@PathVariable String id) {
        return this.userInfoService.getUser2(id);
    }
    @GetMapping("/getUserWithHouse/{id}")
    public UserInfo getUserWithHouse(@PathVariable String id) {
        return this.userInfoService.getUserWithHouse(id);
    }
    @GetMapping("/getUserWithHouse2/{id}")
    public UserInfo getUserWithHouse2(@PathVariable String id) {
        return this.userInfoService.getUserWithHouse2(id);
    }

    @GetMapping("queryAll")
    public List<UserInfo> queryAll() {
        return userInfoService.queryAll();
    }


    @GetMapping("queryAll2")
    public List<UserInfo> queryAll2() {
        return userInfoService.queryAll2();
    }
    @GetMapping("queryAll3")
    public List<UserInfo> queryAll3() {
        return userInfoService.queryAll3();
    }

    @PostMapping("query")
    public List<UserInfo> query(@RequestBody UserDetailBo param) {
        return userInfoService.query2(param);
    }
}
